<?php

App::uses('AppModel', 'Model');

/**

 * City Model

 *

 */

class City extends AppModel {



/**

 * Use table

 *

 * @var mixed False or table name

 */

	public $useTable = 'city';



/**

 * Display field

 *

 * @var string

 */

	public $displayField = 'title';

  protected $_cacheKey = 'city';

/**

 * Validation rules

 *

 * @var array

 */

	public $validate = array(

		'title' => array(

			'notEmpty' => array(

				'rule' => array('notEmpty'),

				//'message' => 'Your custom message here',

				//'allowEmpty' => false,

				//'required' => false,

				//'last' => false, // Stop validation after this rule

				//'on' => 'create', // Limit validation to 'create' or 'update' operations

			),

		),

		'abbrev' => array(

			'notEmpty' => array(

				'rule' => array('notEmpty'),

				//'message' => 'Your custom message here',

				//'allowEmpty' => false,

				//'required' => false,

				//'last' => false, // Stop validation after this rule

				//'on' => 'create', // Limit validation to 'create' or 'update' operations

			),

		),

	);

		public function afterSave($created, $options = array()) {
			parent::afterSave($created, $options = array());
			Cache::delete($this->_cacheKey);
		}
		public function afterDelete() {
			Cache::delete($this->_cacheKey);
		}

	  public function getCity() {
		if ($getCity = Cache::read($this->_cacheKey)) {
		  return $getCity;
		}
		$getCity = $this->find('list', array('conditions'=>array('City.active'=>1),
		));
		Cache::write($this->_cacheKey, $getCity);
		return $getCity;
	  }


}

